<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="数据年份" prop="dataYear">
        <el-select v-model="queryParams.dataYear" placeholder="请选择年份" clearable>
          <el-option
            v-for="item in yearOptions"
            :key="item.dataYear"
            :label="item.dataYear"
            :value="item.dataYear"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="指标级别" prop="indeLevel">
        <el-select v-model="queryParams.indeLevel" placeholder="请选择指标级别" clearable >
          <el-option
            v-for="dict in dict.type.yc_organ_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="填报部室" prop="deptId">
        <el-select v-model="queryParams.deptId" placeholder="请选择填报部室" clearable >
          <el-option
            v-for="item in ycdeptOptions"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptId"/>
        </el-select>
      </el-form-item>


      <el-form-item label="指标名称" prop="indeId">
        <el-select v-model="queryParams.indeId" filterable placeholder="请选择指标" clearable  size="small"
                   :disabled="indeChangeEnable">
          <el-option
            v-for="item in ycindeOptions"
            :key="item.indeId"
            :label="item.indeName"
            :value="item.indeId">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="组织名称" prop="orgId">
        <el-select v-model="queryParams.orgId" filterable placeholder="请选择组织" clearable  size="small">
          <el-option
            v-for="item in ycorgOptions"
            :key="item.orgId"
            :label="item.orgName"
            :value="item.orgId">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="维度值" prop="dataDimension">
        <el-input
          v-model="queryParams.dataDimension"
          placeholder="请输入维度值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="数据值" prop="dataValue">-->
<!--        <el-input-->
<!--          v-model="queryParams.dataValue"-->
<!--          placeholder="请输入数据值"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="维度" prop="dimension">
        <el-select v-model="queryParams.dimension" placeholder="请选择维度" clearable>
          <el-option
            v-for="dict in dict.type.you_dimension"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:data:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleADD"
            v-hasPermi="['system:data:add']"
          >发布数据</el-button>
        </el-col>


      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdds"
          v-hasPermi="['system:data:add']"
        >一键发布</el-button>
      </el-col>

        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdds1"
            v-hasPermi="['system:data:add']"
          >一键发布-厂</el-button>
        </el-col>

        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdds2"
            v-hasPermi="['system:data:add']"
          >一键发布-区</el-button>
        </el-col>

        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdds3"
            v-hasPermi="['system:data:add']"
          >一键发布-站</el-button>
        </el-col>

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:data:add']"-->
<!--        >未达标数据</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:data:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:data:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:data:import']"
        >导入</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:data:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据序号" align="center" prop="dataId" v-if="columns[0].visible"/>
      <el-table-column label="指标名称" align="center" prop="ycInde.indeName" v-if="columns[1].visible"/>
      <el-table-column label="部门id" align="center" prop="ycInde.deptId"  v-if="columns[2].visible"/>
      <el-table-column label="组织名称" align="center" prop="ycOrg.orgName" v-if="columns[3].visible"/>
      <el-table-column label="填报部室" align="center" prop="ycInde.deptId" :formatter="formatDeptName" v-if="columns[11].visible"/>
      <el-table-column label="数据值" align="center" prop="dataValue" v-if="columns[4].visible"/>
      <el-table-column label="维度值" align="center" prop="dataDimension" v-if="columns[5].visible"/>
      <el-table-column label="维度"  align="center" prop="dimension" v-if="columns[6].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.you_dimension" :value="scope.row.dimension"/>
        </template>
      </el-table-column>

      <el-table-column label="状态值" align="center" prop="status" v-if="columns[7].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_status1" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="数据年份"  align="center" prop="dataYear" v-if="columns[8].visible"/>

      <el-table-column label="是否达标" align="center" prop="upToStandard" v-if="columns[9].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.up_to_standard" :value="scope.row.upToStandard"/>
        </template>
      </el-table-column>
      <el-table-column label="措施Id" align="center" prop="meaId" v-if="columns[10].visible"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="getMeasuresImformation(scope.row)"
          >查看措施</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:data:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:data:remove']"
          >删除</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 一键添加对话框 -->
    <el-dialog :title="title1" :visible.sync="open1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据年份" prop="dataYear" >
          <el-input style="width: 220px" v-model="form.dataYear" placeholder="请输入数据年份" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="open1 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 一键添加对话框-厂 -->
    <el-dialog :title="title11" :visible.sync="open11" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据年份" prop="dataYear" >
          <el-input style="width: 220px" v-model="form.dataYear" placeholder="请输入数据年份" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm11">确 定</el-button>
        <el-button @click="open11 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 一键添加对话框-区 -->
    <el-dialog :title="title12" :visible.sync="open12" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据年份" prop="dataYear" >
          <el-input style="width: 220px" v-model="form.dataYear" placeholder="请输入数据年份" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm12">确 定</el-button>
        <el-button @click="open12 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 一键添加对话框-站 -->
    <el-dialog :title="title13" :visible.sync="open13" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据年份" prop="dataYear" >
          <el-input style="width: 220px" v-model="form.dataYear" placeholder="请输入数据年份" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm13">确 定</el-button>
        <el-button @click="open13 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 发布油厂数据管理对话框 -->
    <el-dialog :title="title2" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="数据年份" prop="dataYear" >
          <el-select v-model="form.dataYear" filterable placeholder="请输入数据年份" clearable
                     @change="currentYear"
          >
            <el-option
              v-for="item in indeYearOptions"
              :key="item.indeYear"
              :label="item.indeYear"
              :value="item.indeYear">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="指标级别" prop="indeLevel">
          <el-select v-model="form.indeLevel" placeholder="请选择指标级别" clearable >
            <el-option
              v-for="dict in dict.type.yc_organ_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="填报部室" prop="deptId">
          <el-select v-model="form.deptId" placeholder="请选择填报部室" clearable >
            <el-option
              v-for="item in ycdeptOptions"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId"/>
          </el-select>
        </el-form-item>

        <el-form-item label="指标名称" prop="indeId">
          <el-select v-model="form.indeId" filterable placeholder="请选择指标" clearable
                     :disabled="indeChangeEnableForm"
          >
            <el-option
              v-for="item in ycindeOptionsForm2"
              :key="item.indeId"
              :label="item.indeName"
              :value="item.indeId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="组织序号" prop="orgId">
          <el-select v-model="form.orgId" filterable placeholder="请选择组织" clearable  >
            <el-option
              v-for="item in ycorgOptions"
              :key="item.orgId"
              :label="item.orgName"
              :value="item.orgId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="open2 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改油厂数据管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="数据年份" prop="dataYear" >
          <el-select v-model="form.dataYear" filterable placeholder="请输入数据年份" clearable
          @change="currentYear"
          >
            <el-option
              v-for="item in indeYearOptions"
              :key="item.indeYear"
              :label="item.indeYear"
              :value="item.indeYear">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="指标名称" prop="indeId">
          <el-select v-model="form.indeId" filterable placeholder="请选择指标" clearable
          :disabled="indeChangeEnable"
          >
            <el-option
              v-for="item in ycindeOptionsForm"
              :key="item.indeId"
              :label="item.indeName"
              :value="item.indeId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="组织序号" prop="orgId">
          <el-select v-model="form.orgId" filterable placeholder="请选择组织" clearable  >
            <el-option
              v-for="item in ycorgOptions"
              :key="item.orgId"
              :label="item.orgName"
              :value="item.orgId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="维度值" prop="dataDimension" >
          <el-input style="width: 220px" v-model="form.dataDimension" placeholder="请输入维度值"  />
        </el-form-item>

        <el-form-item label="数据值" prop="dataValue">
          <el-input v-model="form.dataValue" placeholder="请输入数据值" />
        </el-form-item>

        <el-form-item label="维度" prop="dimension">
          <el-select v-model="form.dimension" placeholder="请选择维度">
            <el-option
              v-for="dict in dict.type.you_dimension"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择数据状态">
            <el-option
              v-for="dict in dict.type.data_status1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否达标" prop="upToStandard">
          <el-select v-model="form.upToStandard" placeholder="请选择数据是否达标">
            <el-option
              v-for="dict in dict.type.up_to_standard"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="措施Id" prop="meaId">
          <el-input v-model="form.meaId" placeholder="请输入meaId" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 措施信息对话框 0-->
    <el-dialog :title="meatitle0" :visible.sync="meaopen0" width="500px" append-to-body>
      <el-form ref="meaform" :model="meaform" :rules="rules" label-width="80px">
        <span>当前数据已达标，无改进措施</span>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="meaopen0 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 措施信息对话框 1-->
    <el-dialog :title="meatitle1" :visible.sync="meaopen1" width="500px" append-to-body>
      <el-form ref="meaform" :model="meaform" :rules="rules" label-width="80px">
        <el-form-item label="影响因素" prop="cause">
          <el-input type="textarea" v-model="meaform.cause" placeholder="请输入影响因素" />
        </el-form-item>
        <el-form-item label="改进措施" prop="improvement">
          <el-input type="textarea" v-model="meaform.improvement" placeholder="请输入改进措施" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="meaopen1 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 措施信息对话框 2-->
    <el-dialog :title="meatitle2" :visible.sync="meaopen2" width="500px" append-to-body>
      <el-form ref="meaform" :model="meaform" :rules="rules" label-width="80px">
        <span>当前数据未完成填写审核，达标情况未知</span>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="meaopen2 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 措施信息对话框 2-->
    <el-dialog :title="meatitle3" :visible.sync="meaopen3" width="500px" append-to-body>
      <el-form ref="meaform" :model="meaform" :rules="rules" label-width="80px">
        <span>未找到数据绑定措施</span>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="meaopen3 = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {listData, listDataMore, getData, delData, addData, updateData, ycdatayearSelect,ycdataimportdatas,ycdataimportdatas1,ycdataimportdatas2,ycdataimportdatas3} from "@/api/system/data";
import {getMeasures} from "../../../api/system/measures";
import {ycindeSelect,selectYcIndeYear} from "@/api/system/inde";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {ycorgSelect} from "@/api/system/org";
import {getUserProfile} from "@/api/system/user";
import {getToken} from "@/utils/auth";
import log from "../../monitor/job/log.vue";
import {DeptSelect} from "@/api/system/dept";


export default {
  name: "Data",
  dicts:['you_dimension','data_status1','up_to_standard','yc_organ_level'],
  components:{ Treeselect },
  data() {
    return {
      currentYearNum: null,
      currentIndeLevelNum: null,
      currentDeptId:null,
      currentYearNumForm: null,
      currentIndeLevelNumForm: null,
      currentDeptIdForm:null,
      //指标能否选择
      indeChangeEnable: true,
      indeChangeEnableForm: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //指标下拉选项
      ycindeOptions: [],
      ycindeOptionsForm:[],
      ycindeOptionsForm2:[],
      //组织下拉选项
      ycorgOptions:[],
      //年份选项
      yearOptions:[],
      //指标年份选项
      indeYearOptions:[],
      //部门下拉选项
      ycdeptOptions:[],
      // 总条数
      total: 0,
      // 油厂数据管理表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 一键发布弹出窗标题
      title1: "",
      title11: "",
      title12: "",
      title13: "",
      // 发布弹出窗标题
      title2: "",
      // 措施弹出界面标题
      meatitle0: "",
      meatitle1: "",
      meatitle2: "",
      meatitle3: "",
      // 是否显示弹出层
      open: false,
      // 是否显示一键发布弹出窗
      open1: false,
      open11:false,
      open12:false,
      open13:false,
      // 是否显示发布数据弹出窗
      open2: false,
      // 是否显示措施弹出窗
      meaopen0: false,
      meaopen1: false,
      meaopen2: false,
      meaopen3: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/data/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        indeId: null,
        orgId: null,
        indeLevel:null,
        dataDimension: null,
        dataValue: null,
        dimension: null,
        status: null,
        dataYear: null,
        deptId:null
      },
      //列信息
      columns:[
        {key:0,label:`数据序号`,visible:false},
        {key:1,label:`指标名称`,visible:true},
        {key:2,label:`部门id`,visible:false},
        {key:3,label:`组织名称`,visible:true},
        {key:4,label:`数据值`,visible:true},
        {key:5,label:`纬度值`,visible:true},
        {key:6,label:`维度`,visible:true},
        {key:7,label:`状态值`,visible:true},
        {key:8,label:`数据年份`,visible:true},
        {key:9,label: `是否达标`,visible: true},
        {key:10,label: `措施Id`,visible: false},
        {key:11,label: `填报部室`,visible: true}
      ],
      // 表单参数
      form: {},
      // 措施表单
      meaform:{},
      // 表单校验
      rules: {
      },

    };
  },
  created() {
    this.getList();
    this.getYcIndeSelect();
    this.getYcOrgSelect();
    this.getDataYear();
    this.getIndeYear();
    this.getYcDeptSelect();
  },
  watch:{
    'form.deptId':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentDeptIdForm = null;
        this.currentDeptIdForm = newVaule;
        console.log("currentDeptIdForm is",this.currentDeptIdForm)
        this.getIndeSelectForm(this.currentIndeLevelNumForm)
      }
    },
    'queryParams.deptId':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentDeptId = null;
        this.currentDeptId = newVaule;
        console.log("currentDeptId is",this.currentDeptId)
        this.getIndeSelect(this.currentIndeLevelNum)
      }
    },
    'queryParams.dataYear':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentYearNum = null;
        this.currentYearNum = newVaule;
        console.log("currentYearNum is",this.currentYearNum)
        this.getIndeSelect(this.currentIndeLevelNum)
      }
    },
    'form.dataYear':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentYearNumForm = null;
        this.currentYearNumForm = newVaule;
        console.log("currentYearNumForm is",this.currentYearNumForm)
        this.getIndeSelectForm(this.currentIndeLevelNumForm)
      }
    },

    'queryParams.indeLevel':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentIndeLevelNum = null;
        this.currentIndeLevelNum = newVaule;
        console.log("currentIndeLevelNum is",this.currentIndeLevelNum)
        this.getIndeSelect(this.currentIndeLevelNum)
      }
    },
    'form.indeLevel':{
      deep:true,
      handler(newVaule, oldValue){
        this.currentIndeLevelNumForm = null;
        this.currentIndeLevelNumForm = newVaule;
        console.log("currentIndeLevelNumForm is",this.currentIndeLevelNumForm)
        this.getIndeSelectForm(this.currentIndeLevelNumForm)
      }
    },
  },

  methods: {
    formatDeptName(row){
      for(let i = 0; i < this.ycdeptOptions.length; i++){
        if(this.ycdeptOptions[i].deptId == row.ycInde.deptId){
          return this.ycdeptOptions[i].deptName
        }
      }
    },

    currentYear(val1){
      // this.ycindeOptions = []
      // this.getIndeSelect(val1);
    },
    currentIndeLevel(val2){
      // this.currentIndeLevelNum = null;
      // this.currentIndeLevelNum = val2;
      // this.ycindeOptions = []
      // this.getIndeSelect(val2)
    },
    getIndeSelect(currentIndeLevel){
      this.ycindeOptions = []
      ycindeSelect().then(response =>{
        var tem_ycindeOptions = response.data;
        console.log(tem_ycindeOptions)
        this.indeChangeEnable = true;
        for (let i in tem_ycindeOptions){
          if(this.currentYearNum == tem_ycindeOptions[i].indeYear && currentIndeLevel == tem_ycindeOptions[i].indeLevel && this.currentDeptId == tem_ycindeOptions[i].sysDept.deptId){
            this.ycindeOptions.push(tem_ycindeOptions[i]);
            this.indeChangeEnable = false;
          }
          else continue;
        }

      })
    },
    getIndeSelectForm(currentIndeLevel){
      this.ycindeOptions = []
      this.ycindeOptionsForm2=[]
      ycindeSelect().then(response =>{
        var tem_ycindeOptions = response.data;
        console.log(tem_ycindeOptions)
        this.indeChangeEnableForm = true;
        for (let i in tem_ycindeOptions){
          if(this.currentYearNumForm == tem_ycindeOptions[i].indeYear && currentIndeLevel == tem_ycindeOptions[i].indeLevel && this.currentDeptIdForm == tem_ycindeOptions[i].deptId ){
            this.ycindeOptions.push(tem_ycindeOptions[i]);
            this.ycindeOptionsForm2.push(tem_ycindeOptions[i]);
            this.indeChangeEnableForm = false;
          }
          else continue;
        }
      })
    },
    /**
     * 查看相应指标信息
     * */
    getMeasuresImformation(row){
      if (row.upToStandard == 0){
        this.meaopen0 = true;
      }else if(row.upToStandard == 1){
        if (row.meaId == null){
          this.meaopen3 = true;
        }else {
          getMeasures(row.meaId).then(response =>{
            this.meaform.cause = response.data.cause;
            this.meaform.improvement = response.data.improvement;
            this.meaopen1 = true;
          })
        }
      }else{
        this.meaopen2 = true;
      }

    },

    /** 查询油厂数据管理列表 */
    getList() {
      this.loading = true;
      let deptId;
      getUserProfile().then(response => {
        if (response.roleGroup != "超级管理员") {
          deptId = response.data.deptId;
          this.queryParams.deptId = deptId;
          listDataMore(this.queryParams).then(response => {
            this.dataList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        }else{
          listDataMore(this.queryParams).then(response => {
            this.dataList = response.rows;
            console.log(this.dataList)
            this.total = response.total; //数据条数
            this.loading = false;
          });
        }
      });
    },
    //获取指标年份
    getIndeYear(){
      selectYcIndeYear().then(response =>{
        this.indeYearOptions = response.data;
      })
    },
    //获取年份
    getDataYear(){
      ycdatayearSelect().then(response =>{
        this.yearOptions = response.data;
        console.log(typeof(response.data))
      })
    },
    //获取指标下拉选项
    getYcIndeSelect(){
      ycindeSelect().then(response=>{
        this.ycindeOptions = response.data;
        this.ycindeOptionsForm = response.data
        this.ycindeOptionsForm2 = response.data
      })
    },
    //获取组织下拉选项
    getYcOrgSelect(){
     ycorgSelect().then(response =>{
       this.ycorgOptions = response.data;
     })
    },
    //获取部门下拉选项
    getYcDeptSelect(){
      DeptSelect().then(response =>{
        var deptOptions = [];
        this.ycdeptOptions = response.data;
        deptOptions = this.ycdeptOptions.splice(0, 3)
        console.log("this.ycdeptOptions",this.ycdeptOptions);
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dataId: null,
        indeId: null,
        orgId: null,
        dept: null,
        deptId:null,
        dataDimension: null,
        indeLevel:null,
        dataValue: null,
        createTime: null,
        dimension: null,
        status: 0,
        dataYear: null
      };
      this.indeChangeEnable = true
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
     handleQuery() {
      this.queryParams.pageNum = 1;
      console.log("this.queryParams-------------------------------------")
      console.log(this.queryParams)
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.indeChangeEnable = true
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.dataId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 一键发布按钮操作*/
    handleAdds(){
      this.reset();
      this.open1 = true;
      this.title1 = "一键发布油厂数据";
    },
    /** 一键发布按钮操作*/
    handleAdds1(){
      this.reset();
      this.open11 = true;
      this.title11 = "一键发布油厂数据-厂";
    },
    /** 一键发布按钮操作*/
    handleAdds2(){
      this.reset();
      this.open12 = true;
      this.title12 = "一键发布油厂数据-区";
    },
    /** 一键发布按钮操作*/
    handleAdds3(){
      this.reset();
      this.open13 = true;
      this.title13 = "一键发布油厂数据-站";
    },
    /** 发布数据按钮操作*/
    handleADD(){
      this.reset();
      this.open2 = true;
      this.title2 = "发布油厂数据";
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加油厂数据管理";
      // listData().then(response=>{
      //   this.ycorgOption = [];
      //   const data = {orgId: 0,orgName:'顶级节点', children:[]};
      //   data.children = this.handleTree(response.data,"ycOrg.orgId","ycOrg.parentId");
      //   this.ycorgOption.push(data);
      // });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dataId = row.dataId || this.ids
      getData(dataId).then(response => {
        this.form = response.data;
        this.form.dimension = this.form.dimension.toString();
        this.form.status = this.form.status.toString();
        this.form.upToStandard = this.form.upToStandard.toString();
        this.open = true;
        this.title = "修改油厂数据管理";
      });
    },
    //一键发布提交
    submitForm1() {
      ycdataimportdatas(this.form);
      this.$modal.msgSuccess("修改成功");
      this.open1 = false;
      this.getList();
    },
    submitForm11() {
      ycdataimportdatas1(this.form);
      this.$modal.msgSuccess("修改成功");
      this.open11 = false;
      this.getList();
    },
    submitForm12() {
      ycdataimportdatas2(this.form);
      this.$modal.msgSuccess("修改成功");
      this.open12 = false;
      this.getList();
    },
    submitForm13() {
      ycdataimportdatas3(this.form);
      this.$modal.msgSuccess("修改成功");
      this.open13 = false;
      this.getList();
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dataId != null) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 发布提交按钮 */
    submitForm2() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            this.form.status = 0;
            this.form.upToStandard = 2;
            addData(this.form).then(response => {
              this.$modal.msgSuccess("发布成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const dataIds = row.dataId || this.ids;
      this.$modal.confirm('是否确认删除油厂数据管理编号为"' + dataIds + '"的数据项？').then(function() {
        return delData(dataIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "指标导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/data/importTemplate', {
      }, `data_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
